package cases 
{
	import com.bit101.components.ProgressBar;
	import com.bit101.components.PushButton;
	import com.bit101.components.Slider;
	import com.sociodox.theminer.TheMiner;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import mx.core.SoundAsset;
	//import org.despair2D.ui.StatsKai;
	import org.despair2D.Despair;
	import org.despair2D.utils.*;
	

	
public class SoundDemo extends Sprite 
{
	private var progress:ProgressBar
	[Embed(source="../soundAsset.swf", mimeType="application/octet-stream")]private var soundAssets:Class
	public function SoundDemo() 
	{
		
		//addChild(new StatsKai())
		addChild(new TheMiner())
		Despair.startup(stage)
		//Despair.process.addUpdateListener(function():void{;trace(SfxManager.getInstance().numSfx)})
		Despair.embeded.loadBytes(new soundAssets(), onLoadSound)
	}
	
	
	private function onLoadSound():void
	{
		Despair.embeded.dispose()
		
		var slider:Slider
		var pauseBtn:PushButton
		
		
		pauseBtn = new PushButton(this, 200, 130, 'toggle', function (e:MouseEvent):void{MusicManager.getInstance().paused = !MusicManager.getInstance().paused})
		pauseBtn.setSize(50, 20)
		
		pauseBtn = new PushButton(this, 300, 130, 'reset', function(e:MouseEvent):void{MusicManager.getInstance().reset()})
		pauseBtn.setSize(50, 20)
		
		pauseBtn = new PushButton(this, 400, 130, 'stop', function(e:MouseEvent):void{MusicManager.getInstance().stop()})
		pauseBtn.setSize(50, 20)
		
		pauseBtn = new PushButton(this, 500, 130, 'play', function(e:MouseEvent):void { MusicManager.getInstance().loadAndPlay('初日.mp3', 1, 1,false) } )
		pauseBtn.setSize(50, 20)
		
		MusicManager.getInstance().addEventListener(ProgressEvent.PROGRESS, p)
		progress = new ProgressBar(this, 600, 130)
		
		
		slider = new Slider(Slider.HORIZONTAL, this, 200, 200)
		slider.setSliderParams(0, 1, 1)
		slider.addEventListener(Event.CHANGE, function(e:Event):void
		{
			var s:Slider = e.target as Slider
			MusicManager.getInstance().totalVolume = s.value
		});
		
		//pauseBtn = new PushButton(this, 200, 330, 'sfxA', function(e:MouseEvent):void { SfxManager.getInstance().loadAndPlay('Greeeen.mp3', 1, 1) } )
		pauseBtn = new PushButton(this, 200, 330, 'sfxA', function(e:MouseEvent):void { SfxManager.getInstance().play('sfx_Call', 1, 1) } )
		pauseBtn.setSize(50,20)
		//pauseBtn = new PushButton(this, 300, 330, 'sfxB', function(e:MouseEvent):void { SfxManager.getInstance().loadAndPlay('Akb48.mp3', 1, 1) } )
		pauseBtn = new PushButton(this, 300, 330, 'sfxB', function(e:MouseEvent):void { SfxManager.getInstance().play('sfx_Chip', 1, 1) } )
		pauseBtn.setSize(50,20)
		FrameTimerManager.getInstance().addTimer(0.5,0).addRoundListener( function():void { SfxManager.getInstance().play('sfx_Call', 1, 1) } ).start();
		slider = new Slider(Slider.HORIZONTAL, this, 200, 400)
		slider.setSliderParams(0, 1, 1)
		slider.addEventListener(Event.CHANGE, function(e:Event):void
		{
			var s:Slider = e.target as Slider
			SfxManager.getInstance().totalVolume = s.value
		});
		
		pauseBtn = new PushButton(this, 350, 400, 'StopAll', function(e:MouseEvent):void{SfxManager.getInstance().stopAll()})
		pauseBtn.setSize(50, 20)
		pauseBtn = new PushButton(this, 350, 450, 'Enable', function(e:MouseEvent):void{SfxManager.getInstance().enabled = !SfxManager.getInstance().enabled})
		pauseBtn.setSize(50, 20)
		pauseBtn = new PushButton(this, 400, 330, 'StopSfx', function(e:MouseEvent):void{SfxManager.getInstance().stopSfx(1)})
		pauseBtn.setSize(50, 20)
		
		
	}
	
	private function p(e:ProgressEvent):void
	{
		progress.value = e.bytesLoaded
		progress.maximum = e.bytesTotal
		//trace(e.bytesLoaded, e.bytesTotal)
	}


}

}